# -*- coding: utf-8 -*-
"""
@ Created on 2024-06-14 12:23
---------
@summary: 数据库初始化脚本
---------
@author: Lsaiah
"""

import asyncio
import os
from db import create_tables
from log import logger

async def main():
    """主函数"""
    logger.info("开始初始化数据库...")
    
    try:
        # 创建数据库表
        await create_tables()
        logger.info("数据库初始化完成！")
        
    except Exception as e:
        logger.error(f"数据库初始化失败: {str(e)}")
        return False
    
    return True

if __name__ == "__main__":
    # 设置环境变量
    os.environ["ENV"] = "dev"
    
    # 运行初始化
    success = asyncio.run(main())
    
    if success:
        print("✅ 数据库初始化成功！")
    else:
        print("❌ 数据库初始化失败！")
        exit(1)

